import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

/**
 * 输入整型数组和排序标识，对其元素按照升序或降序进行排序
 */
public class HJ101 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int n = scanner.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(scanner.nextInt());
            }
            int flag = scanner.nextInt();

            list.sort(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    if(o1.equals(o2)){
                        return 0;
                    }
                    return o1 > o2?1:-1;
                }
            });

            if(flag == 0){
                for (Integer num : list) {
                    System.out.print(num+" ");
                }
            }
            if(flag == 1){
                for (int i = list.size() - 1; i >= 0; i--) {
                    System.out.print(list.get(i)+" ");
                }
            }
        }
    }
}
